﻿using System;
using System.Collections.Generic;
using System.Text;

namespace System
{
    public class ArrayHelper
    {
        /// <summary>
        /// 拼接数组
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="array1"></param>
        /// <param name="array2"></param>
        /// <returns></returns>
        public static T[] Combine<T>(T[] array1, T[] array2)
        {
            int allcount = 0, a1count = 0, a2count = 0;
            if (array1 != null)
            {
                a1count = array1.Length;
            }
            if (array2 != null)
            {
                a2count = array2.Length;
            }
            allcount = a1count + a2count;
            T[] newt = new T[allcount];
            for (int i = 0; i < a1count; i++)
            {
                newt[i] = array1[i];
            }
            for (int i = 0; i < a2count; i++)
            {
                newt[i] = array2[i + a1count];
            }
            return newt;
        }

        /// <summary>
        /// 比较两个数组的元素是否相同
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="array1"></param>
        /// <param name="array2"></param>
        /// <returns></returns>
        public static bool EqualsArray<T>(T[] array1, T[] array2)
        {
            if (array1 == null)
            {
                return array2 == null;
            }
            if (array2 == null)
            {
                return false;
            }
            if (array1.Length != array2.Length)
            {
                return false;
            }
            for (int i = 0; i < array1.Length; i++)
            {
                if (!array1[i].Equals(array2[i]))
                {
                    return false;
                }
            }
            return true;
        }
    }
}
